package tcln.sors.model.core.dao;

import tcln.sors.model.core.dom.Entity;

/**
 * A application-specific version of a DAO registry which returns {@link Dao} everytime method {@link #getDaoFor(Class)}
 * is called. See {@link ch.elca.el4j.services.persistence.generic.dao.DaoRegistry} for the idea of DAO Registry.
 * 
 * @author Truong Chau Lien Ngoc (lienngoc@gmail.com)
 * @see ch.elca.el4j.services.persistence.generic.dao.DaoRegistry
 */
public interface DaoFactory {

    /**
     * Returns a DAO for given entity type.
     * 
     * @param <D>
     *            DAO concrete type.
     * @param <T>
     *            Entity type.
     * @param entityType
     *            Entity type.
     * @param desireDaoType
     *            Desired DAO type.
     * @return An implementation of {@link Dao} for given entity type.
     */
    <D extends Dao<T>, T extends Entity<Integer>> D getDaoFor(Class<T> entityType, Class<D> desireDaoType);

    /**
     * Returns a DAO for given entity type.
     * 
     * @param <T>
     *            Entity type.
     * @param entityType
     *            Entity type.
     * @return An implementation of {@link Dao} for given entity type.
     */
    <T extends Entity<Integer>> Dao<T> getDaoFor(Class<T> entityType);
    
    /**
     * Flushes current active session.
     */
    void flushSession();
}
